﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibraryManagerTests.Model
{

    /// <summary>
    /// Helper class to generate arbitrary length random Unicode strings.
    /// 
    /// Author: "Ben"
    /// Copied from: http://www.bonf.net/2009/01/14/generating-random-unicode-strings-in-c/
    /// </summary>
    class RandomUnicodeString
    {
        private Random _r;

        public RandomUnicodeString()
        {
            _r = new Random();
        }

        public string GetString(int length)
        {
            byte[] str = new byte[length * 2];

            for (int i = 0; i < length * 2; i += 2)
            {
                int chr = _r.Next(0xD7FF);
                str[i + 1] = (byte) ((chr & 0xFF00) >> 8);
                str[i] = (byte) (chr & 0xFF);
            }

            return Encoding.Unicode.GetString(str);
        }
    }

}
